<template>
	<div>
		<el-form ref="form" :model="form" label-width="80px">

			<el-form-item label="用户名">
				<el-input v-model="form.username"></el-input>
			</el-form-item>


			<el-form-item label="密码">
				<el-input v-model="form.password"></el-input>
			</el-form-item>

			<el-form-item label="真实姓名">
				<el-input v-model="form.realname"></el-input>
			</el-form-item>
			<el-form-item label="电话">
				<el-input v-model="form.telephone"></el-input>
			</el-form-item>
			<el-form-item label="科室">
				<el-select v-model="form.deptId" placeholder="请选择">
					<el-option v-for="item in depts" :key="item.id" :label="item.name" :value="item.id">
					</el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="医生级别">
				<el-select v-model="form.registLevel" placeholder="请选择">
					<el-option v-for="item in registLevels" :key="item.id" :label="item.name" :value="item.id">
					</el-option>
				</el-select>
			</el-form-item>

			<el-form-item>
				<el-button type="primary" @click="save">保存</el-button>
			</el-form-item>
		</el-form>

	</div>
</template>

<script>
	export default {
		name: 'UserEdit',
		components: {

		},
		props: [
			'showEdit',
			'userId'
		],
		data() {
			return {
				form: {
					userId: '',
					username: '',
					password: '',
					realname: '',
					telephone: '',
					deptId:'',
					registLevel:''
				},
				depts:[],
				registLevels:[]
				// depts:[
				// 	{id:1,name:'肾内科'},
				// 	{id:2,name:'消化内科'}
				// ],
				// registLevls:[
				// 	{id:1,name:'专家'},
				// 	{id:2,name:'教授'}
				// ]
			}
		},
		methods: {
			save() {
				this.axios.get('/user?type=save', (data) => {
					if (data) {
						this.$emit('update:showEdit', false)
						this.$emit('update')
					}

				}, this.form, '保存成功');
			},
			loadData(){
				//加载机构列表
				this.axios.get('/dept?type=listAll', (data) => {
					this.depts = data;
				});
				
				//加载机构列表
				this.axios.get('/regist_level?type=queryList', (data) => {
					this.registLevels = data;
				});
			}
			
			
			
		},
		created() {

			if (this.userId) {
				//当修改的时候 需要根据用户的 id， 将数据查询到页面
				this.axios.get('/user?type=toEdit', (data) => {
					this.form = data;
				}, {
					userId: this.userId
				});
			}
			
			//加载 科室、挂号级别信息
			this.loadData();

		}
	}
</script>

<style>
</style>
